package com.water.camera.mark;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.water.camera.bean.EditItem;
import com.water.camera.databinding.LayoutWatermark61Binding;

import java.text.SimpleDateFormat;
import java.util.ArrayList;

public class Mark61 extends BaseMark {

    LayoutWatermark61Binding binding;

    public Mark61(@NonNull Context context) {
        super(context);
    }

    public Mark61(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public Mark61(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void init(int type) {
        if (type == 0) {
            binding = LayoutWatermark61Binding.inflate(LayoutInflater.from(getContext()));
            addView(binding.getRoot());
            hideView(binding.bottom);
            for (int i = 3; i < binding.mid.getChildCount(); i++) {
                binding.mid.getChildAt(i).setVisibility(View.GONE);
            }
        } else {
            binding = LayoutWatermark61Binding.inflate(LayoutInflater.from(getContext()), this, true);
        }
        update();
    }

    @Override
    public void update() {
        setText(binding.binding1, "title61", binding.binding1);
        setText(binding.binding3, "no61", binding.binding2);
        setText(binding.binding5, "count61", binding.binding4);
        setText(binding.binding7, "type61", binding.binding6);
        setText(binding.binding9, "content61", binding.binding8);
        setText(binding.binding11, "area61", binding.binding10);
        setText(binding.binding13, "charge61", binding.binding12);
        setText(binding.binding15, "time61", binding.binding14);
        setTime(binding.binding15, new SimpleDateFormat("yyyy.MM.dd HH:mm"));

        setText(binding.binding17, "weather61", binding.binding16);
        setText(binding.binding19, "didian61", "在这里", binding.binding18);
        setText(binding.binding21, "height61", binding.binding20);
        setText(binding.binding23, "angle61", binding.binding22);
        setText(binding.binding25, "speed61", binding.binding24);
        setText(binding.binding27, "jingwei61", binding.binding26);
        String[] ss = new EditItem("jingwei61").getStringPoints();
        binding.binding27.setText(ss[1]);
        binding.binding29.setText(ss[0]);
        setText(binding.binding31, "result61", binding.binding28);

        setText(binding.binding33, "wuye61", binding.binding32);
        setText(binding.binding35, "xiaoqu61", binding.binding34);
        setText(binding.binding37, "fire61", binding.binding36);
        setText(binding.binding39, "water61", binding.binding38);
        setText(binding.binding41, "elec61", binding.binding40);

        super.update();
    }

    @Override
    public ArrayList<EditItem> getEditItems() {
        ArrayList<EditItem> list = new ArrayList<>();
        list.add(new EditItem("title61", "标题"));
        list.add(new EditItem("no61", "编号"));
        list.add(new EditItem("count61", "计数"));
        list.add(new EditItem("type61", "巡检类型"));
        list.add(new EditItem("content61", "巡检内容"));
        list.add(new EditItem("area61", "巡检区域"));
        list.add(new EditItem("charge61", "巡检人"));
        list.add(new EditItem("time61", "拍摄时间", true));

        list.add(new EditItem("weather61", "天气"));

        list.add(new EditItem("didian61", "地点"));
        list.add(new EditItem("height61", "海拔"));
        list.add(new EditItem("angle61", "方位角"));
        list.add(new EditItem("speed61", "速度"));

        list.add(new EditItem("jingwei61", "经纬度"));

        list.add(new EditItem("result61", "巡检结果"));

        list.add(new EditItem("wuye61", "物业单位"));
        list.add(new EditItem("xiaoqu61", "小区名称"));
        list.add(new EditItem("fire61", "消防设施"));
        list.add(new EditItem("water61", "水煤管道"));
        list.add(new EditItem("elec61", "用电安全"));

        return list;
    }

    @Override
    public void onValueChange(EditItem item) {
        if (item.isTime) {
            setTime(binding.binding15, new SimpleDateFormat("yyyy.MM.dd HH:mm"));
        } else if ("jingwei61".equals(item.key)) {
            String[] ss = new EditItem("jingwei57").getStringPoints();
            binding.binding27.setText(ss[1]);
            binding.binding29.setText(ss[0]);
        } else {
            super.onValueChange(item);
        }
    }

    @Override
    public void onShowChange(EditItem item) {
        if ("jingwei61".equals(item.key)) {
            if (item.show) {
                showView(binding.binding26, binding.binding28);
            } else {
                hideView(binding.binding26, binding.binding28);
            }
        } else {
            super.onShowChange(item);
        }
    }
}
